package view;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JLabel;
import javax.swing.border.EmptyBorder;/** * A class to encapsulate the linking to the BNF website * @author Gideon Pyzer * */
@SuppressWarnings("serial")
public class BNFLink extends JLabel{

	public BNFLink(){

		final URI uri;
		try {
			uri = new URI("http://bnf.org/");
			this.setBorder(new EmptyBorder(2,8,2,8));
			this.setText("<html><span style=\"color: #000099;\">BNF Website</span></html>");
			this.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent e) {
					openLink(uri);
				}
				public void mouseEntered(MouseEvent e){
					BNFLink.this.setText("<html><span style=\"color: #990990\">BNF Website</span></html>");
					BNFLink.this.setCursor(new Cursor(Cursor.HAND_CURSOR));
				}
				public void mouseExited(MouseEvent e) {
					BNFLink.this.setText("<html><span style=\"color: #000099;\">BNF Website</span></html>");
				}
			});
		} catch (URISyntaxException e1){
			e1.printStackTrace();
		}
	}	/**	 * Opens the specified URI	 * @param uri the link to open	 */
	private static void openLink(URI uri) 
	{
		if (Desktop.isDesktopSupported()) {
			Desktop desktop = Desktop.getDesktop();
			try{
				desktop.browse(uri);
			} catch (IOException e) {
				Designer.getInstance().showMessageDialog("Cannot open browser");
			}
		} else {
			Designer.getInstance().showMessageDialog("Cannot open browser");
		}
	}
}
